import { storage } from '@/util'
import { Commit, Dispatch } from 'vuex'

const CACHE_COLLAPSED: string = '__collapsed'
const name = <string>import.meta.env.VITE_APP_NAME;
const collapsed = <boolean>storage.get(CACHE_COLLAPSED, false)

interface IAppState {
    appName: string;
    sideCollapsed: boolean;
}

interface Ctx {
    commit: Commit,
    dispatch: Dispatch,
    state: IAppState
}
const state = (): IAppState => ({
    appName: name,
    sideCollapsed: collapsed,
})

const mutations = {
    setAppName(state: IAppState, name: string) {
        state.appName = name
    },
    setCollapsed(state: IAppState, value: boolean) {
        state.sideCollapsed = value
        storage.set(CACHE_COLLAPSED, value)
    },
};
const actions = {};

export default { namespaced: true, state, mutations, actions }
